<template>
  <div class="headicon-container">
    <div class="mui-bar mui-bar-nav">
        <span class=" mui-pull-left mui-icon mui-icon-left-nav" @click='hideIcon'></span>
        <span class=" mui-pull-left icon-text">头像</span>
    </div>
    <div class="headicon-content">
        <img :src="imgSrc || this.$imHeadIcon" alt="找不到图片">
    </div>
    <div class="changeHeadIcon">
        <input type="file" @change='iconChange'>
        <span class="text">更换头像</span>
    </div>
  </div>
</template>

<script>
import {mapState, mapActions} from 'vuex'
export default {
    props: {
        imgSrc: {
            type: String,
            default: this.$imHeadIcon
        }
    },
    computed: {
        ...mapState(['currentLoginUser'])
    },
    mounted() {
        console.log(this.$imHeadIcon, 'yyyyyyyyyyyyy')
    },
    methods: {
        ...mapActions(['sendFile']),
        iconChange(e) {
            // console.log(e)
            // console.log(e.path)
            const self = this
            if (e.path) {
                // 后面修改单个文件上传为多个文件上传
                // console.log(e.path[0].files)
                let obj = {
                    // 文件前缀名字
                    filePrefix: self.currentLoginUser.username + '/headIcon',
                    name: e.path[0].files[0].name,
                    size: e.path[0].files[0].size,
                    time: e.path[0].files[0].lastModifiedDate,
                    type: 'headIcon'
                }
                let blob = new Blob([e.path[0].files[0]], {'type': null})
                // console.log(blob)
                obj['file'] = blob
                // action上传文件
                self.sendFile(obj)
            }
            // 隐藏点击头像之后展示的界面
            // this.$emit('hideClickheadiconZi')
        },
        hideIcon() {
            // 隐藏点击头像之后展示的界面
            this.$emit('hideClickheadiconZi')
            // console.log(123)
        }
    }
}
</script>

<style lang='scss' scoped>
.headicon-container{
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 12;
    background: white;
    .changeHeadIcon{
        position: relative;
        top: 6vh;
        left: 30%;
        width: 40vw;
        height: 6vh;
        border-radius: 10px;
        background-color: rgb(10, 197, 10);
        text-align: center;
        line-height: 6vh;
        input {
            position: absolute;
            top: 0;
            left: 0;
            display: block;
            width: 100%;
            height: 100%;
            opacity: 0;
        }
        .text {
            color: white;
        }
    }
}
.headicon-content{
    width: 100vw;
    height: 100vw;
    background-color: aliceblue;
    line-height: 100vw;
    text-align: center;
    padding-top: 5vw;
    img{
        width: 90vw;
        height: 90vw;
    }
    margin-top: 45px;
}
.icon-text{
    line-height: 46px;
}
</style>
